package com.example.stumanager.student;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.stumanager.R;
import com.example.stumanager.database.RepairSql;
import com.example.stumanager.entity.RepairEntity;

/**
 * 提交报修信息页面
 */
public class StudentRepairPage extends AppCompatActivity {
    EditText t1,t2,t3,t4;
    Button re;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.student_repair_page);
        t1=findViewById(R.id.name);
        t2=findViewById(R.id.id);
        t3=findViewById(R.id.address);
        t4=findViewById(R.id.et_5);
        Button submit=findViewById(R.id.submit);
        re = findViewById(R.id.re);
        re.setOnClickListener(view -> finish());
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(t1.getText().toString().equals("") ||
                        t2.getText().toString().equals("") ||
                        t3.getText().toString().equals("")||
                        t4.getText().toString().equals("") ){
                    Toast.makeText(StudentRepairPage.this, "不能为空", Toast.LENGTH_SHORT).show();
                    return ;
                }
                RepairEntity f=new RepairEntity(t1.getText().toString(),t2.getText().toString(),
                        t3.getText().toString(),t4.getText().toString());
                RepairSql db=new RepairSql(getBaseContext());
                if(db.add(f)){
                    Toast.makeText(StudentRepairPage.this, "添加成功", Toast.LENGTH_SHORT).show();

                }else{
                    Toast.makeText(StudentRepairPage.this, "添加失败", Toast.LENGTH_SHORT).show();
                }

            }
        });

    }
}